package com.itheima.producer;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.sun.javafx.robot.FXRobotImage;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author zero
 * @date 2020/6/14
 */
public class Producer_WorkQueues {

    public static void main(String[] args) throws IOException, TimeoutException {

        //1.创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //2.设置参数
        factory.setHost("192.168.83.128");
        factory.setPort(5672);
        factory.setVirtualHost("/zero");
        factory.setUsername("zero");
        factory.setPassword("zero");
        //3.创建链接 Connection
        Connection connection = factory.newConnection();
        //4.创建 Channel
        Channel channel = connection.createChannel();
        //5.创建队列 Queue
        channel.queueDeclare("work_queues",true,false,false,null);

        for (int i = 1; i <= 10; i++) {
            //6.发送消息
            String body = i+"hello rabbitmq ... ";
            channel.basicPublish("","hello_world",null,body.getBytes());
        }
        //7.释放资源
        channel.close();
        connection.close();
    }
}
